package online.westonline.com.westonline.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import online.westonline.com.westonline.R;
import online.westonline.com.westonline.entry.GaideBean;
import online.westonline.com.westonline.ui.MeetingGaideActivity;

/**
 * 模板适配器
 * Created by xiatao on 2018/8/24.
 */

public class GaideAdpter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<GaideBean> gaideBeans = new ArrayList<>();

    public void setGaideBeans(List<GaideBean> gaideBeans) {
        this.gaideBeans = gaideBeans;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gaide_item, parent, false);
        return new GaideViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof GaideViewHolder) {
            final GaideBean gaideBean = gaideBeans.get(position);
            GaideViewHolder viewHolder = (GaideViewHolder) holder;
            viewHolder.tvGaideDescrible.setText(gaideBean.getDesc());
            viewHolder.tvGaideName.setText(gaideBean.getName());
            viewHolder.imgMeGaide.setBackgroundResource(gaideBean.getResid());
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (gaideBean.getId()==0)
                    {
                        Bundle bundle = new Bundle();
                        bundle.putInt("time",0);
                        Intent intent = new Intent(holder.itemView.getContext(), MeetingGaideActivity.class);
                        intent.putExtras(bundle);
                        holder.itemView.getContext().startActivity(intent);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return gaideBeans == null ? 0 : gaideBeans.size();
    }

    class GaideViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_me_gaide)
        ImageView imgMeGaide;
        @BindView(R.id.tv_gaide_name)
        TextView tvGaideName;
        @BindView(R.id.tv_gaide_describle)
        TextView tvGaideDescrible;


        public GaideViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
